/**
 * Created by George on 2018/2/25.
 */

import util from "../common/util"

// 将本控制器函数作为结果返回给router.js
var createUserCtrl = function ($scope, $http, $state) {
    $scope.welcome_info = "会员管理";
    $scope.user = {
        name: "",
        dues: 0,
        info: "",
        joinDate: util.getNowFormatDate()
    };
    $scope.$emit('updateRoute', 'user');

    $scope.addMemberClick = function () {
        var data = {
            "name": $scope.user.name,
            "dues": $scope.user.dues,
            "info": $scope.user.info,
            "joinDate": $scope.user.joinDate
        };
        $http.post('/basketballfire/rest/user', data).then(function (req) {
            console.log("success!");
            alert("创建成功！");
            $state.go("user");
        }, function (req) {
            console.log("failed!");
            alert("创建失败！");
        });
    };

    function initOrUpdateData() {
        $scope.user = {
            name: "",
            dues: 0,
            info: "",
            joinDate: util.getNowFormatDate()
        };
    }

    function init() {
        initOrUpdateData();
    }

    //ctrl start
    init();
};

export default createUserCtrl;